package com.ruoyi.quality.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.quality.domain.InspectionBasis;
import com.ruoyi.quality.service.IInspectionBasisService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 检测检验依据Controller
 * 
 * @author ruoyi
 * @date 2023-10-17
 */
@RestController
@RequestMapping("/quality/basis")
@Api(value="检测检验依据",tags = "检测检验依据")
public class InspectionBasisController extends BaseController
{
    @Autowired
    private IInspectionBasisService inspectionBasisService;

    /**
     * 查询检测检验依据列表
     */
    @GetMapping("/list")
    @ApiOperation(value="查询检测检验依据列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "pageNum", value = "页数", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "pageSize", value = "每页记录数", required = true, dataType = "String"),
    })
    public TableDataInfo list(InspectionBasis inspectionBasis)
    {
        startPage();
        List<InspectionBasis> list = inspectionBasisService.selectInspectionBasisList(inspectionBasis);
        return getDataTable(list);
    }

    /**
     * 导出检测检验依据列表
     */
    @Log(title = "检测检验依据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InspectionBasis inspectionBasis)
    {
        List<InspectionBasis> list = inspectionBasisService.selectInspectionBasisList(inspectionBasis);
        ExcelUtil<InspectionBasis> util = new ExcelUtil<InspectionBasis>(InspectionBasis.class);
        util.exportExcel(response, list, "检测检验依据数据");
    }

    /**
     * 获取检测检验依据详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation(value="获取检测检验依据详细信息")
    @ApiImplicitParam(paramType="query", name = "id", value = "主键", required = true, dataType = "String")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(inspectionBasisService.selectInspectionBasisById(id));
    }

    /**
     * 根据设备类别获取检测检验依据详细信息
     */
    @GetMapping(value = "/getInfoByEquType/{equType}")
    @ApiOperation(value="获取检测检验依据详细信息")
    public AjaxResult getInfoByEquType(@PathVariable("equType") String equType)
    {
        return success(inspectionBasisService.selectInspectionBasisByEquType(equType));
    }

    /**
     * 新增检测检验依据
     */
    @Log(title = "检测检验依据", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value="新增检测检验依据")
    public AjaxResult add(@ApiParam(name="检测检验依据",value="传入json格式",required=true)@RequestBody InspectionBasis inspectionBasis)
    {
        inspectionBasis.setId(IdUtils.fastSimpleUUID());
        return toAjax(inspectionBasisService.insertInspectionBasis(inspectionBasis));
    }

    /**
     * 修改检测检验依据
     */
    @Log(title = "检测检验依据", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value="修改检测检验依据")
    public AjaxResult edit(@ApiParam(name="检测检验依据",value="传入json格式",required=true)@RequestBody InspectionBasis inspectionBasis)
    {
        return toAjax(inspectionBasisService.updateInspectionBasis(inspectionBasis));
    }

    /**
     * 删除检测检验依据
     */
    @Log(title = "检测检验依据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation(value="删除检测检验依据")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(inspectionBasisService.deleteInspectionBasisByIds(ids));
    }
}
